<template>
  <div class="app-container">
    <el-card class="search-card">
      <el-row :gutter="40" class="panel-group">
        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
          <div class="card-panel">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="团队" class-name="card-panel-icon"/>
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                总学生人数
              </div>
              <count-to :start-val="0" :end-val="studentScoreStatisticsDataVo.totalStudentNum" :duration="3600" class="card-panel-num"/>
            </div>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
          <div class="card-panel">
            <div class="card-panel-icon-wrapper icon-shopping">
              <svg-icon icon-class="详情" class-name="card-panel-icon"/>
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                平均成绩
              </div>
              <count-to :start-val="0" :end-val="studentScoreStatisticsDataVo.averageScore" :duration="3600" class="card-panel-num"/>
            </div>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
          <div class="card-panel">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="团队" class-name="card-panel-icon"/>
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                不及格成绩人数
              </div>
              <count-to :start-val="0" :end-val="studentScoreStatisticsDataVo.failNum" :duration="2600" class="card-panel-num"/>
            </div>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
          <div class="card-panel">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="团队" class-name="card-panel-icon"/>
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                优秀成绩人数
              </div>
              <count-to :start-val="0" :end-val="studentScoreStatisticsDataVo.excellentNum" :duration="2600" class="card-panel-num"/>
            </div>
          </div>
        </el-col>

      </el-row>
    </el-card>

    <el-card class="table-card">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane v-for="item in scoreList" :label="item.label" :name="item.activeName">
          <el-table :data="item.studentScoreVoList">
            <el-table-column label="序号" align="center" prop="id" />
            <el-table-column label="学号" align="center" prop="studentNum" />
            <el-table-column label="学院名称" align="center" prop="depName" />
            <el-table-column label="专业名称" align="center" prop="subjectName" />
            <el-table-column label="课程名称" align="center" prop="subjectCourseName" />
            <el-table-column label="上课老师" align="center" prop="teacherName" />
            <el-table-column label="学期" align="center" prop="semester" />
            <el-table-column label="成绩" align="center" prop="score">
              <template slot-scope="scope">
                <span :style="scope.row.score < 60 ? 'color:red' : ''">{{ scope.row.score }}</span>
              </template>
            </el-table-column>
            <el-table-column label="课程类型" align="center" prop="studyRequire">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.study_require" :value="scope.row.studyRequire"/>
              </template>
            </el-table-column>
            <el-table-column label="学分" align="center" prop="credits" />
            <el-table-column label="绩点" align="center" prop="gradePoint" />
            <el-table-column label="创建时间" align="center" prop="createTime" />
            <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                >修改</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>

    </el-card>

  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import { scoreDetail } from "@/api/course/score";

export default {
  components: {
    CountTo
  },
  dicts: ['study_require'],
  name: "Info",
  data() {
    return {
      courseId: null,
      scoreList: [],

      activeName: '0',
      studentScoreStatisticsDataVo: {},
    };
  },
  created() {
    this.courseId = this.$route.params && this.$route.params.courseId;
    this.getList()
  },
  methods: {
    getList(){
      scoreDetail(this.courseId).then(response => {
        this.scoreList = response.data;
        this.studentScoreStatisticsDataVo = this.scoreList[0].studentScoreStatisticsDataVo;
      });
    },
    handleClick(tab, event) {
      // 根据activeName 过滤出 scoreList 中的数据
      this.studentScoreStatisticsDataVo = this.scoreList.filter(item => {
        return item.activeName == tab.name
      })[0].studentScoreStatisticsDataVo;
    }
  }
};
</script>

<style lang="scss" scoped>
.panel-group {
  //margin-top: 18px;

  .card-panel-col {
    margin-bottom: 16px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
